import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const usePinia = defineStore('pinia1', () => {
  // 相当于state
  const num = ref(1)

  // 相当于getters
  const dobuleNum = computed(() => {
    return num.value * 2
  })

  const add = payload => {
    num.value += payload
  }
  const sub = payload => {
    setTimeout(() => {
      num.value -= payload
    }, 1000)
  }
  return {
    num,
    dobuleNum,
    add,
    sub
  }
})
